package mygame;

import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Node;
import com.jme3.texture.Texture2D;

/**
 * This is the Main Class of your Game. You should only do initialization here.
 * Move your Logic into AppStates or Controls
 * @author normenhansen
 */
public class GoldMain extends SimpleApplication {

    public static void main(String[] args) {
        GoldMain app = new GoldMain();
        app.start();
    }

    @Override
    public void simpleInitApp() {
        Node goldScene = (Node) assetManager.loadModel("Scenes/goldScene.j3o");
        PassUtil passUtil = new PassUtil(assetManager, renderManager);
        Texture2D renderTexture2D = passUtil.genRenderSceneTexture2D(goldScene, "Sphere", assetManager.loadMaterial("Materials/Gold/GoldUVMaterial.j3m"), cam, cam.getWidth(), cam.getHeight(), 0x001);
        Texture2D blur1 = passUtil.genConvolutionTexture2D(cam, renderTexture2D, 0x002, 0x003, 512, 512, 1, 15, 2, 512);
        Texture2D blur2 = passUtil.genConvolutionTexture2D(cam, renderTexture2D, 0x004, 0x005, 512, 512, 1, 25, 3, 512);
        Texture2D blur3 = passUtil.genConvolutionTexture2D(cam, renderTexture2D, 0x006, 0x007, 512, 512, 1, 25, 4, 512);
        Material goldPass1 = assetManager.loadMaterial("Materials/Gold/GoldMaterial.j3m");
//        goldPass1.setTexture("Blur1Map", renderTexture2D);
//        goldPass1.setTexture("Blur2Map", blur1);
//        goldPass1.setTexture("Blur3Map", blur2);
//        goldPass1.setTexture("Blur4Map", blur3);
        goldScene.getChild("Sphere").setMaterial(goldPass1);
        Node mainCamera = (Node) goldScene.getChild("mainCamera");
        cam.setLocation(mainCamera.getWorldTranslation());
        cam.setRotation(mainCamera.getWorldRotation());
        cam.setFrustumPerspective(45.0f, cam.getWidth() * 1.0f / cam.getHeight(), 0.01f, 500.0f);
        flyCam.setMoveSpeed(Float.parseFloat(mainCamera.getUserData("moveSpeed").toString()));

        rootNode.attachChild(goldScene);
    }

    @Override
    public void simpleUpdate(float tpf) {
        //TODO: add update code
    }

    @Override
    public void simpleRender(RenderManager rm) {
        //TODO: add render code
    }
}
